<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <style>
      body{color:#999;font:12px/1.5 Tahoma;}
      #outer{width:500px;margin:0 auto;}
      #outer input{padding:3px;border:1px solid #ccc;font-family:inherit;width:220px;margin-right:10px;}
      .sum{font-size:30px;color:red;}
    </style>
  </head>
  <body>
    
    <div id="outer">
      <label>
        <input value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" type="text"><span>输入数字求和，数字之间用半角","号分隔</span>
      </label>
      <p><button>求和</button></p>
      <strong class="sum">188</strong>
    </div>


    <script>
    window.onload = function() {
      var oInput = document.getElementsByTagName('input')[0],
          oButton = document.getElementsByTagName('button')[0],
          oSum = document.getElementsByTagName('strong')[0];

      oInput.onkeyup = function() {
        this.value = this.value.replace(/[^(\d)|(,)]/, '');
      }

      oButton.onclick = function() {
        var sum = 0;
        oInput = oInput.value.split(',');
        for (var i in oInput) {
          sum += parseInt(oInput[i]);
        }

        oSum.innerHTML = sum;
      }
    }


    </script>    
  </body>
</html>